#include "Base/AsyncLogger.h"
#include "Base/Logger.h"
#include <thread>

using namespace toym;

void threadFunc() {
    for (int i = 1; i <= 10000; ++i) {
        LOG_DEBUG << " in threadFunc " << i;
        if (i%100 == 0)
            AsyncLogger::flushLog();
    }
}

int main(int argc, char* argv[]) {
    auto pLogger = AsyncLogger::getInstance();
    pLogger->setProcessName(argv[0]);
    pLogger->startThread();
    LogPuter::setOutputFunc(&AsyncLogger::putLog);
    LogPuter::setFlushFunc(&AsyncLogger::flushLog);

    std::thread t(threadFunc);

    for (int i = 1; i <= 10000; ++i) {
        LOG_INFO << "in main " << i;
        if (i%100 == 0)
            AsyncLogger::flushLog();
    }

    t.join();
    std::this_thread::sleep_for(std::chrono::seconds(1));
}
